package cn.yx.common.redis.pojo;

import lombok.Getter;
import lombok.Setter;

import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * <p>Redis缓存对象封装</p>
 *
 * @author Wgssmart
 */
@Getter
@Setter
public class RedisCacheObject {

    /**
     * key
     */
    private String key;
    /**
     * 值
     */
    private Object value;
    /**
     * 大小
     */
    private Long size;
    /**
     * 失效时长
     */
    private Long expiration;
    /**
     * 失效时间对应的单位
     */
    private TimeUnit timeUnit;
    /**
     * 失效时间点
     */
    private Instant expirationAt;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RedisCacheObject that = (RedisCacheObject) o;
        return Objects.equals(key, that.key);
    }

    @Override
    public int hashCode() {
        return Objects.hash(key);
    }
}
